<template>
  <div ref="mainCon" class="container">
    <topTitle
      v-if="!hiddleToolBar"
      :titleText="titleText"
      :titleExplain="titleExplain"
    ></topTitle>
    <div class="mainCon">
      <el-row class="tipBar2">
        <el-col class="hint">
          <div class="imgLabel">
            <img
              src="../../../static/img/declare/declarePro.png"
              class="picCss"
            />
          </div>
          <div class="hintCss">
            <div>1.申报项目</div>
            <span class="fontCss">施工方申报项目</span>
          </div>
        </el-col>
        <el-col class="stepCss">
          <img src="../../../static/img/salary/stepLine.png" class="lineCss" />
        </el-col>
        <el-col class="hint">
          <div class="imgLabel">
            <img
              src="../../../static/img/declare/auditReport.png"
              class="picCss"
            />
          </div>
          <div class="hintCss">
            <div>2.等待审核</div>
            <span class="fontCss">等待当地监管部门审核申报内容</span>
          </div>
        </el-col>
        <el-col class="stepCss">
          <img src="../../../static/img/salary/stepLine.png" class="lineCss" />
        </el-col>
        <el-col class="hint">
          <div class="imgLabel">
            <img
              src="../../../static/img/declare/approved.png"
              class="picCss"
            />
          </div>
          <div class="hintCss">
            <div>
              3.审核通过
              <el-tooltip content="Top center" placement="top" effect="dark">
                <div slot="content">
                  审核驳回怎么办？根据监管部门驳回理由
                  <br />修改项目信息后重新申报即可
                </div>
                <i class="icon iconfont iconhuabanfuben"></i>
              </el-tooltip>
            </div>
            <!-- <el-tooltip content="Bottom center" placement="bottom" effect="dark">
              <div slot="content">
                审核通过后企业可管理项目，项目经理
                <br />可使用手机号码注册账号管理项目
              </div>
              <span class="fontCss ellipsis">审核通过后企业可管理项目,项目经理可使用手机号码注册账号管理项目</span>
            </el-tooltip> -->
            <span class="fontCss"
              >审核通过后企业可管理项目，项目经理可使用手机号码注册账号管理项目</span
            >
          </div>
        </el-col>
      </el-row>
      <el-row class="toolbar searchInputWidth" style="padding-bottom: 0">
        <el-form :inline="true" :model="filterField" ref="searchConditions">
          <el-col :lg="8" :xl="6">
            <el-form-item label="区域" class="row-padding-bottom">
              <el-cascader
                ref="manageArea"
                v-model="areaId"
                :options="areasOptions"
                @change="getAreaId"
                clearable
                filterable
                :props="{ checkStrictly: true }"
                :append-to-body="false"
              ></el-cascader>
            </el-form-item>
          </el-col>
          <el-col :lg="8" :xl="6">
            <el-form-item label="行业" class="row-padding-bottom">
              <el-select
                v-model="filterField.industryId"
                filterable
                placeholder="请选择"
                clearable
                :popper-append-to-body="false"
              >
                <el-option
                  v-for="item in industryOptions"
                  :key="item.code"
                  :label="item.name"
                  :value="item.code"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <template v-if="advanced">
            <el-col :lg="8" :xl="6">
              <el-form-item label="项目名称" class="row-padding-bottom">
                <el-input
                  v-model="filterField.projectName"
                  placeholder="请输入项目名称"
                  clearable
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :lg="8" :xl="6">
              <el-form-item label="申报日期" class="row-padding-bottom">
                <el-date-picker
                  v-model="date"
                  type="daterange"
                  unlink-panels
                  :picker-options="pickerOptions"
                  range-separator="至"
                  start-placeholder="开始日期"
                  end-placeholder="结束日期"
                  value-format="yyyy-MM-dd"
                  :append-to-body="false"
                >
                </el-date-picker>
              </el-form-item>
            </el-col>
            <el-col :lg="8" :xl="6">
              <el-form-item label="申报状态" class="row-padding-bottom">
                <el-select
                  v-model="filterField.status"
                  filterable
                  placeholder="请选择"
                  clearable
                  :popper-append-to-body="false"
                >
                  <el-option
                    v-for="item in statusOptions"
                    :key="item.id"
                    :label="item.name"
                    :value="item.id"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <!-- <el-form-item>
            <el-button type="primary" icon="icon iconfont iconchazhao1" @click="searchList" class="commonBtn"></el-button>
          </el-form-item> -->
          </template>
          <el-col :lg="8" :xl="6">
            <el-form-item label="">
              <a
                @click="toggleAdvanced"
                style="margin-left: 40px; color: #409eff; cursor: pointer"
                class="btnColor"
              >
                {{ advanced ? '收起' : '展开' }}
                <i
                  :class="advanced ? 'el-icon-arrow-up' : 'el-icon-arrow-down'"
                ></i>
              </a>
              <el-button
                type="primary"
                icon="icon iconfont iconchazhao1"
                @click="searchList"
                class="searchBtn"
              >
                <span>搜索</span>
              </el-button>
            </el-form-item>
            <el-form-item>
              <exportBtn
                :dataLen="tableList.length"
                :filterField="filterField"
                api="api-s/report/export_JC_CS_PROJECT_AUDIT"
              ></exportBtn>
            </el-form-item>
          </el-col>
        </el-form>
      </el-row>
      <div class="spacing"></div>
      <div
        ref="tableBox"
        :class="hiddleToolBar ? 'tableBoxCur tableBox' : 'tableBoxCur'"
      >
        <el-table
          ref="tableBox1"
          :max-height="tableHeight"
          :data="tableList"
          v-loading="loading"
          :header-cell-style="{ background: '#eef1f6', color: '#606266' }"
          border
          @header-dragend="handleDragend"
          @sort-change="sortChange"
          highlight-current-row
          stripe
          style="border: 1px solid #dfe6ec"
        >
          <el-table-column label="项目名称" width="230">
            <template slot-scope="scope">
              <copyText
                :tableIndex="scope.$index"
                :copyTextName="scope.row.projectName"
                :columnName="'projectName'"
              ></copyText>
            </template>
          </el-table-column>
          <el-table-column label="项目地址" width="230">
            <template slot-scope="scope">
              <copyText
                :tableIndex="scope.$index"
                :copyTextName="scope.row.address"
                :columnName="'address'"
              ></copyText>
            </template>
          </el-table-column>
          <el-table-column label="建设方" width="230">
            <template slot-scope="scope">
              <copyText
                :tableIndex="scope.$index"
                :copyTextName="scope.row.pcName"
                :columnName="'pcName'"
              ></copyText>
            </template>
          </el-table-column>
          <el-table-column label="施工方" width="230">
            <template slot-scope="scope">
              <copyText
                :tableIndex="scope.$index"
                :copyTextName="scope.row.pbName"
                :columnName="'pbName'"
              ></copyText>
            </template>
          </el-table-column>
          <el-table-column
            prop="applyDate"
            label="申报时间"
            sortable="custom"
            align="center"
            width="120px"
            :formatter="dateForma"
          ></el-table-column>
          <el-table-column
            prop="statusDesc"
            label="申报状态"
            align="center"
            width="120px"
            :formatter="formatTd"
          ></el-table-column>
          <el-table-column label="驳回原因" width="230">
            <template slot-scope="scope">
              <copyText
                :tableIndex="scope.$index"
                :copyTextName="scope.row.reason"
                :columnName="'reason'"
              ></copyText>
            </template>
          </el-table-column>
          <el-table-column
            label="操作"
            align="left"
            :formatter="formatTd"
            fixed="right"
            width="110"
          >
            <template slot-scope="scope">
              <el-link
                type="primary"
                v-show="isShowDetail"
                @click="toDetail(scope.$index, scope.row)"
                >查看详情</el-link
              >
              <span v-show="!isShowDetail">--</span>
            </template>
          </el-table-column>
          <!-- 表格数据为空时，页面显示 -->
          <div slot="empty" v-show="isShow">
            <emptyTable emptyText="暂无相关信息"></emptyTable>
          </div>
        </el-table>
        <!-- filterField为搜索条件 -->
        <!-- getTableList为获取子组件的数据 -->
        <Pagination
          ref="pagination"
          @getpageNo="getpageNo"
          @getpageSize="getpageSize"
          @getList="getTableList"
          :filterField="filterField"
          :requestUrl="requestUrl"
        ></Pagination>
      </div>
    </div>
  </div>
</template>

<script>
import scrollTable from '@/mixin/scrollTable.js'
import { mapActions, mapState } from 'vuex'

export default {
  name: 'projectAuditList',
  mixins: [scrollTable],
  data() {
    return {
      titleText: '项目审核',
      advanced: false,
      titleExplain:
        '工程项目由施工方进行申报，申报需地区监管部门审核，审核通过后企业即可管理该项目',
      pickerOptions: {
        disabledDate(time) {
          return time.getTime() > Date.now()
        },
      },
      statusOptions: [], //申报状态
      //表格数据
      tableList: [],
      requestUrl: 'api-p/projectapplication/expand/listbypage',
      date: [],
      //搜索条件
      filterField: {
        projectName: '', //项目名称
        status: '', //申报状态
        applyStartDate: '', //开始时间
        applyEndDate: '', //结束时间
        areaId: '', //区域
        industryId: '', //行业
      },
      pageSize: 20,
      pageNo: 1,
      employeeId: '', //务工id
      isShow: false, //列表加载
      loading: true,
      areaId: '', //区域
      pageNos: 1,
      isShowDetail: '',
    }
  },
  computed: { ...mapState(['areasOptions', 'industryOptions']) },
  created() {
    this.$store.state.activeMenu = '/home/project/projectAuditList'

    this.filterField.status = this.$route.query.status
      ? this.$route.query.status
      : ''
    this.areaId = this.$route.query.areaId ? this.$route.query.areaId : ''
    this.filterField.areaId = this.areaId
    this.filterField.projectName = this.$route.query.projectName
      ? this.$route.query.projectName
      : ''
    this.filterField.industryId = this.$route.query.industryId
      ? this.$route.query.industryId
      : ''
    this.date[0] = this.$route.query.applyStartDate
      ? this.$route.query.applyStartDate
      : ''
    this.date[1] = this.$route.query.applyEndDate
      ? this.$route.query.applyEndDate
      : ''
    this.pageNos = this.$route.query.pageNos
      ? parseInt(this.$route.query.pageNos)
      : 1
    this.$nextTick(function () {
      this.$refs.pagination.getTableListData()
    })
    this.getStatus() //获取申报状态
    //获取区域
    this.getAreas({ areaId: this.$store.state.areaInfoArr.areaId })
    //获取行业
    this.getIndustry({})
    this.isShowDetail =
      this.$store.state.buttonLimitsArr.indexOf('projectAudit:detail') > -1 ||
      this.$store.state.buttonLimitsArr.indexOf('projectDeclareList:detail') >
        -1
  },
  activated() {
    this.$nextTick(function () {
      this.$refs.pagination.getTableListData(this.pageNo, this.pageSize)
    })
  },
  methods: {
    toggleAdvanced() {
      this.advanced = !this.advanced
    },
    getpageSize(val) {
      this.pageSize = val
    },
    getpageNo(val) {
      this.pageNo = val
    },
    ...mapActions(['getAreas', 'getIndustry']),
    // getpageNo(val){

    //   this.pageNos = val
    // },
    getTableList(data) {
      this.tableList = data
      this.loading = false
      if (this.tableList.length < 1) {
        this.isShow = true
      }
    },
    getStatus() {
      this.axios({
        method: 'post',
        url: 'api-p/projectapplication/expand/status',
        data: {},
      })
        .then((response) => {
          this.statusOptions = response.data.result
        })
        .catch((error) => {
          this.$message({
            showClose: true,
            duration: 3000,
            message: '获取申报状态数据失败',
            type: 'error',
          })
        })
    },
    // 搜索
    searchList() {
      this.pageSize = 20
      this.pageNo = 1
      if (this.date) {
        this.filterField.applyStartDate = this.date[0]
        this.filterField.applyEndDate = this.date[1]
      } else {
        this.filterField.applyStartDate = ''
        this.filterField.applyEndDate = ''
      }
      this.$refs.pagination.getTableListData()
    },
    //跳转详情
    toDetail(index, row) {
      const {
        projectName,
        status,
        applyStartDate,
        applyEndDate,
        areaId,
        industryId,
      } = this.filterField
      this.$router.push({
        path: '/home/project/projectDeclareDetail',
        name: 'projectDeclareDetail',
        query: {
          id: row.id,
          projectName,
          status,
          applyStartDate,
          applyEndDate,
          areaId,
          industryId,
          pageNos: this.pageNos,
        },
      })
      this.$store.commit('CHANGE_SLIDER_NAME', {
        oldUrl: '/home/project/projectAuditList',
        newUrl: this.$router.currentRoute.fullPath,
      })
    },
    dateForma: function (row, column) {
      const daterc = row[column.property]
      if (daterc != null) {
        return daterc
      } else {
        return '--'
      }
    },
    //获取选中的区域最后一级id
    getAreaId() {
      var areaId = this.areaId[this.areaId.length - 1]
      this.filterField.areaId = areaId
    },
  },
}
</script>

<style lang="less" scoped>
/* .topTitle {
    height: 67px;
    background-color: #e4ebf1;
    padding-left: 24px;
    font: bold 18px Microsoft YaHei;
    padding-top: 10px;
  } */
.mainCon {
  top: 210px;
  @media only screen and (max-width: 1366px) {
    /deep/.searchInputWidth .el-form--inline .el-form-item__label {
      width: 80px;
    }
  }
}
.tipBar2 {
  height: 88px;
  margin: 16px 20px 35px 20px;
}
.hint {
  float: left;
  display: block;
  width: 24%;
  padding-left: 5%;
}
.imgLabel {
  display: inline-block;
  /* width: 80px; */
  float: left;
}
.picCss {
  /* height: 80px;
    width: 80px;
    font-size: 88px; */
  color: #d0d0d8;
}
.lineCss {
  width: 100%;
  height: 8px;
  margin-top: 40px;
}
.stepCss {
  float: left;
  display: block;
  width: 12%;
}
.hintCss {
  display: block;
  margin-left: 85px;
  margin-top: 15px;
}
.fontCss {
  font-size: 14px;
  color: #666;
  display: block;
  /* text-overflow: -o-ellipsis-lastline;
      overflow: hidden;
      text-overflow: ellipsis;
      display: -webkit-box;
      -webkit-line-clamp: 2;
      line-clamp: 2;
      -webkit-box-orient: vertical; */
}
.noRule {
  text-align: center;
  img {
    margin: 60px 0;
  }
}
@media screen and (min-width: 1280px) and (max-width: 1366px) {
  .searchInputWidth /deep/ .el-form-item__label {
    width: 70px;
  }
}
@import '../../../static/css/filterArea.less';
</style>
